#include <iostream>
#include <memory>
//类的内部用独占指针
class Girl;
class Boy
{
public:
    Boy()
    {
        std::cout << "Boy构造!\n"; 
    }
    ~Boy()
    {
        std::cout << "Boy析构!\n"; 
    }
    void SetGirl(std::shared_ptr<Girl>& g)
    {
        girlfriend = g;
    }
private:
    //不会引起引用计数器的变换
    std::shared_ptr<Girl> girlfriend;
};

class Girl
{
public:
    Girl()
    {
        std::cout << "Girl构造!\n"; 
    }
    ~Girl()
    {
        std::cout << "Girl析构!\n"; 
    }
    void SetBoy(std::shared_ptr<Boy> &b)
    {
        boyfriend = b;
    }
private:
    //不会引起引用计数器的变换
    std::shared_ptr<Boy> boyfriend;
};

int main()
{
    std::shared_ptr<Boy> b = std::make_shared<Boy>();

    std::shared_ptr<Girl> g = std::make_shared<Girl>();

    b->SetGirl(g);
    g->SetBoy(b);
    return 0;
}